//
//  HZ_Radio_ViewController.m
//  HZ_Beautiful_Music
//
//  Created by dllo on 16/4/5.
//  Copyright © 2016年 ui. All rights reserved.
//

#import "HZ_Radio_ViewController.h"
#import "HZ_Radio_tableCell.h"
#import "HSAFNetTool.h"
#import "HZ_Radio_Model.h"
#import "HZ_TwotableViewCell.h"
#import "HZ_play_hs_Model.h"
@interface HZ_Radio_ViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *table;
@property (nonatomic, strong) UITableView *tableview;
@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic, strong) NSMutableArray *dataTwoArray;
@property (nonatomic, assign) NSInteger isbool;
@property (nonatomic, strong) NSMutableArray *array;
@end

@implementation HZ_Radio_ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _isbool = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width / 4, self.view.bounds.size.height) ];
    _table.backgroundColor = [UIColor colorWithWhite:0.872 alpha:1.000];
    [_table registerClass:[HZ_Radio_tableCell class] forCellReuseIdentifier:@"HZ_Radio_tableCell"];
    _table.delegate = self;
    _table.dataSource = self;
//    关闭滑动
    _table.scrollEnabled = NO;
//    关闭横线
    _table.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_table];
    
    self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(self.view.bounds.size.width / 4, 0, 3 * self.view.bounds.size.width / 4, self.view.bounds.size.height) style:UITableViewStylePlain];
    
    
    [_tableview registerClass:[HZ_TwotableViewCell class] forCellReuseIdentifier:@"HZ_TwotableViewCell"];
    
    self.tableview.delegate = self;
    self.tableview.dataSource = self;
    [self.view addSubview:_tableview];
    
    
    [_tableview reloadData];
    [self RadioHsAFetTool];
    
}

-(void)RadioHsAFetTool{
    
    [HSAFNetTool GETNetWithUrl:@"http://api.fm.ttpod.com/radio?image_type=240_200&utdid=VRu%2Blc%2FVSokDANuKLLSuSY%2B5" body:nil headerFile:nil response:HSJSON success:^(id result) {
        self.dataArray = [NSMutableArray arrayWithCapacity:0];
        for (NSDictionary *dic in result[@"data"]) {
            
            HZ_Radio_Model *model = [[HZ_Radio_Model alloc] initWithDataSource:dic];
            
            
            
            [_dataArray addObject:model];
            
            
        }
        self.dataTwoArray = [NSMutableArray arrayWithCapacity:0];
        
        HZ_Radio_Model *model = _dataArray[0];
        
        
        
        self.dataTwoArray = [NSMutableArray arrayWithArray:model.data];
        
        NSLog(@"data%@", _dataArray);
        [self.table reloadData];
        
        [self.tableview reloadData];
    } failure:^(NSError *error) {
        
    }];
    
    
    
    
    
    
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
    
    
    if ([tableView isEqual:_table]) {
        return _dataArray.count;
    }else if ([tableView isEqual:_tableview]){

        return _dataTwoArray.count;
        
    }
    
    return 0;
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if ([tableView isEqual:_table]) {
        
        HZ_Radio_tableCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HZ_Radio_tableCell"];
        cell.isCurrentIndex = _isbool == indexPath.row;
        NSLog(@"%ld", _isbool);
        NSLog(@"%@",/* DISABLES CODE */ (YES)?@"YES":@"NO", cell.isCurrentIndex);
        NSLog(@"%ld", (long)indexPath.row);
        
        cell.model = _dataArray[indexPath.item];
        return cell;
        
    } else{
        
        HZ_TwotableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HZ_TwotableViewCell"];
        
        
        cell.model = _dataTwoArray[indexPath.row];
        
        
        return cell;
        
        
    }
    
    
    
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if ([tableView isEqual:_table]) {
        return self.view.bounds.size.height / 10;
    } else {
        
        
        return self.view.bounds.size.height / 5;
        
    }
    
    
    
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
   
    if ([tableView isEqual:_table]) {
        [_table deselectRowAtIndexPath:indexPath animated:YES];
       
        self.dataTwoArray = [NSMutableArray arrayWithCapacity:0];

        HZ_Radio_Model *model = _dataArray[indexPath.row];
        _isbool = indexPath.row;
        self.dataTwoArray = [NSMutableArray arrayWithArray:model.data];

//        NSLog(@"%ld", _dataTwoArray.count);
        [_table reloadData];
        [_tableview reloadData];
        
    }else{
       
        [_tableview deselectRowAtIndexPath:indexPath animated:YES];
        
        HZ_DataArray_Model *model = _dataTwoArray[indexPath.row];
        
        
        [HSAFNetTool GETNetWithUrl:[NSString stringWithFormat:@"http://api.fm.ttpod.com/radio/%ld/songs?userid=0&page_size=5&page_num=1", model.tag_id] body:nil headerFile:nil response:HSJSON success:^(id result) {
            self.array = [NSMutableArray arrayWithCapacity:0];
            for (NSDictionary *dic in result[@"data"]) {
                HZ_play_hs_Model *model = [[HZ_play_hs_Model alloc] initWithDataSource:dic];
                [_array addObject:model];
            }
            
            NSMutableArray *arr = [NSMutableArray arrayWithCapacity:0];
            
            [arr addObject:_array];
            
            NSString *str = [NSString stringWithFormat:@"%ld", indexPath.row];
            
            [arr addObject:str];
            
            NSNotificationCenter *hshotrow = [NSNotificationCenter defaultCenter];
            [hshotrow postNotificationName:@"hshotrow" object:arr userInfo:nil];
            
            NSLog(@"%@", result);
            
            [_tableview reloadData];
        } failure:^(NSError *error) {
            
        }];
        
        
        
        NSLog(@"%ld", model.tag_id);
        
        
    }
    
    
    
    
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
